/**
 * 【题】统计字符串中出现次数最多的字符以及次数
 */

// 利用Map生成字符串和字符串出现次数的键值对，再去找最大的值
const getMaxCountInStr = (str) => {
    const newMap = new Map()
    for (let letter of str) {
        if (newMap.has(letter)) {
            newMap.set(letter, newMap.get(letter) + 1)
        } else {
            newMap.set(letter, 1)
        }
    }

    const maxCount = Math.max(...newMap.values())

    const maxCountLetters = []
    newMap.forEach((item, key) => {
        if (item === maxCount) {
            maxCountLetters.push(key)
        }
    });
    return { maxCountLetters, maxCount }
}

console.log(getMaxCountInStr("abcabcab"))